var searchPageObj = {
    el: '#pageApp',
    data: {
       searchType:'',
       searchKey:'',
       artileList:[],
       categoryId:'',
    },
    components:{

    },
    methods: {
      getTinyArticleList:function(){
        var _this = this;
        g.ajax({
          type: 'GET',
          url: g.url.format('/api/author/getTinyArticleList'),
          data:{ text:_this.searchKey, categoryId: _this.categoryId},
          success: function (result) {
             _this.setArticleList(result.data);   
          }
        });
      },
      setArticleList:function(data){
        var _this = this;
        if(_this.searchType == 1){
          data.forEach(function (item) {
            item.img = g.url.imgFormat(item.img);
            _this.artileList.push(item);
          });
        }else if(_this.searchType == 2){
          data.forEach(function (item) {
            item.imgs = item.img.split(',');
            item.img = g.url.imgFormat(item.imgs[0]);
            _this.artileList.push(item);
          });
        }
      },
      tirggerSearch:function(){
        this.artileList.splice(0);
        if(!this.searchKey){
          return;
        }
        this.getTinyArticleList();
      },
      toArticleDetail:function(id){
        g.window.openNew(g.url.urlHref('/page/articleDetail.html?id='+ id +'&type='+ this.searchType));
      },
      closeSearchPage:function(){
        history.go(-1);
      }
    },
    mounted:function () {
      this.searchType = g.params.get('type') || 1; 
      if(this.searchType == 1){
        this.categoryId = -1;
      }else if(this.searchType == 2){
        this.categoryId = 3;
      }
    }
};
var initPage = function(){
  new Vue(searchPageObj);
};